ListNode *detectCycle(ListNode *head) {
        if(!head || !head->next) return nullptr;

        ListNode *fast = head, *slow = head;

        while(fast)
        {
            slow = slow->next;
            if(!fast->next) return nullptr;
            fast = fast->next->next;
            
            if(fast == slow) // 相遇点不一定是入环点
            {
                ListNode *ptr = head;
                while(ptr != slow)
                {
                    ptr = ptr->next;
                    slow = slow->next;
                }
                return ptr;
            }
        }
        return nullptr;
    }